<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计费后台管理</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/managercss.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/wbox.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/wbox.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/validate.js"></script>
<script type="text/javascript">
<!--
	$(function(){
		$(".list div").mousemove(function(){
			$(this).css("background","#E3EEFF");
		}).mouseout(function(){
			$(this).css("background","");
		});
		$("#addMobile").click(function(){
			var wBox = $("#ajax").wBox({
				requestType: "iframe",
				iframeWH:{width:900,height:500},
				target:"<%=request.getContextPath() %>/admin/mobile/${company.companyId}/new",
				title: "添加新的手机型号"
			});
			wBox.showBox();
		});
	});

	function del(companyId,mobileTypeId){
		if(confirm("你确认删除该手机型号吗?")){
			$.ajax({
				url:"<%=request.getContextPath() %>/admin/mobile/del/"+mobileTypeId,
				type:"GET",
				success:function(flag){
					if(flag=='1'){
						alert("删除成功!");
						window.location.href="<%=request.getContextPath() %>/admin/mobile/"+companyId;
					}else{
						alert("删除失败!");
					}
				}
			});
		}
	}

	function updateShow(mobileTypeId){
		$.ajax({
			url:"<%=request.getContextPath() %>/admin/mobile/show/"+mobileTypeId,
			type:"GET",
			dataType:"json", 
			success:function(json){
				var htmlStr = "<form id=\"updateForm\" class=\"democss\"><table>";
				htmlStr += "<tr><th>机型名称:</th><td><input type=\"text\" name=\"mobileTypeName\" id=\"mobileTypeName\" size=30 value=\""+json.mobileTypeName+"\" /></td></tr>";
				htmlStr += "<tr><th>宽度:</th><td><input type=\"text\" name=\"mobileWidth\" id=\"mobileWidth\" size=30 value=\""+json.mobileWidth+"\" /></td></tr>";
				htmlStr += "<tr><th>高度:</th><td><input type=\"text\" name=\"mobileHeight\" id=\"mobileHeight\" size=30 value=\""+json.mobileHeight+"\" /></td></tr>";
				htmlStr += "<tr><th>软件版本:</th><td><input type=\"text\" name=\"softwareVersion\" id=\"softwareVersion\" size=30 value=\""+json.softwareVersion+"\" /></td></tr>";
				htmlStr += "<input type=\"hidden\" name=\"mobileTypeId\" id=\"mobileTypeId\" value=\""+json.mobileTypeId+"\" />";
				htmlStr += "<input type=\"hidden\" name=\"companyId\" id=\"companyId\" value=\""+json.companyId+"\" />";
				htmlStr += "<tr><th></th><td><input type=\"button\" value=\"修改\" class=\"submit\" onclick=\"update("+json.companyId+");wBox.close();\"/></td></tr>";
				htmlStr += "</table></form>";
				var wBox=$("#pop").wBox({
					title: "修改手机型号",
					html: htmlStr
				});
				wBox.showBox();
			}
		});
	}

	function update(companyId){
		var mobileTypeName = $("#mobileTypeName").val();
		var mobileWidth = $("#mobileWidth").val();
		var mobileHeight = $("#mobileHeight").val();
		var softwareVersion = $("#softwareVersion").val();
		if(isNull(mobileTypeName)){
			alert("请输入机型名称!");
			$("#mobileTypeName").focus();
			return;
		}else if(isNull(mobileWidth)||!isNum(mobileWidth)){
			alert("请输入正确的宽度!");
			$("#mobileWidth").focus();
			return;
		}else if(isNull(mobileHeight)||!isNum(mobileHeight)){
			alert("请输入正确的高度!");
			$("#mobileHeight").focus();
			return;
		}else if(isNull(softwareVersion)){
			alert("请输入软件版本号!");
			$("#softwareVersion").focus();
			return;
		}else{
			var date = $("#updateForm").formSerialize();
			$.ajax({
				url:"<%=request.getContextPath() %>/admin/mobile/update",
				data:date,
				type:"POST",
				success:function(flag){
					if(flag=='1'){
						alert("修改成功!");
						window.location.href="<%=request.getContextPath() %>/admin/mobile/"+companyId;
					}else{
						alert("修改失败!");
					}
				}
			});
			return;
		}
	}

	function addProduct(companyId,mobileTypeId){
		var wBox = $("#ajax").wBox({
			requestType: "iframe",
			iframeWH:{width:900,height:500},
			target:"<%=request.getContextPath() %>/admin/mobile/"+companyId+"/"+mobileTypeId,
			title: "内置产品"
		});
		wBox.showBox();
	}
//-->
</script>
</head>
<body>
<div class="information">
	<div class="title">
		<a href="<%=request.getContextPath()%>/admin/company">厂商</a>==>${company.companyName }==>机型管理
	</div>
	<div class="listTitle">
		<ul>
			<li style="width:80px;">编号(CID)</li>
			<li style="width:200px;">机型名称</li>		
			<li style="width:100px;">宽度</li>
			<li style="width:100px;">高度</li>
			<li style="width:100px;">软件版本</li>
			<li style="width:150px;">创建时间</li>
			<li style="width:150px;">操作</li>
		</ul>
		<div class="clear"></div>
	</div>
	<div class="list">
		<c:forEach items="${pageBean.result}" var="mobile" varStatus="status">
			<div class="${status.index%2==0?'noselect':'select' }">
				<ul>
					<li style="width:80px;">${mobile.mobileTypeId  }</li>
					<li style="width:200px;">${mobile.mobileTypeName }</li>		
					<li style="width:100px;">${mobile.mobileWidth }</li>
					<li style="width:100px;">${mobile.mobileHeight }</li>
					<li style="width:100px;">${mobile.softwareVersion }</li>
					<li style="width:150px;">${mobile.createTime }</li>
					<li style="width:150px;">
						<a href="#" onclick="del('${mobile.companyId }','${mobile.mobileTypeId }')">删除</a>
						<a href="#" onclick="updateShow('${mobile.mobileTypeId }')">修改</a>
						<a href="#" onclick="addProduct('${mobile.companyId }','${mobile.mobileTypeId }');" >内置产品</a>
					</li>
				</ul>
				<div class="clear"></div>
			</div>
		</c:forEach>
	</div>
	<jsp:include page="../page.jsp" flush="true"></jsp:include>
	<div class="search">
		<input type="button" name="addMobile" id="addMobile" value="添加新的机型==>>" />
	</div>
</div>
</body>
</html>